﻿using System;

namespace Aeon.Emulator.Instructions
{
    internal static class Prefixes
    {
        [Opcode("F0", Name = "lock:", IsPrefix = true)]
        public static void Lock(VirtualMachine vm)
        {
            vm.Processor.PrefixCount++;
        }
        [Opcode("2E", Name = "cs:", IsPrefix = true, OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void CSOverride(VirtualMachine vm)
        {
            vm.Processor.SegmentOverride = SegmentRegister.CS;
            vm.Processor.PrefixCount++;
        }
        [Opcode("36", Name = "ss:", IsPrefix = true, OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void SSOverride(VirtualMachine vm)
        {
            vm.Processor.SegmentOverride = SegmentRegister.SS;
            vm.Processor.PrefixCount++;
        }
        [Opcode("3E", Name = "ds:", IsPrefix = true, OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void DSOverride(VirtualMachine vm)
        {
            vm.Processor.SegmentOverride = SegmentRegister.DS;
            vm.Processor.PrefixCount++;
        }
        [Opcode("26", Name = "es:", IsPrefix = true, OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void ESOverride(VirtualMachine vm)
        {
            vm.Processor.SegmentOverride = SegmentRegister.ES;
            vm.Processor.PrefixCount++;
        }
        [Opcode("64", Name = "fs:", IsPrefix = true, OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void FSOverride(VirtualMachine vm)
        {
            vm.Processor.SegmentOverride = SegmentRegister.FS;
            vm.Processor.PrefixCount++;
        }
        [Opcode("65", Name = "gs:", IsPrefix = true, OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void GSOverride(VirtualMachine vm)
        {
            vm.Processor.SegmentOverride = SegmentRegister.GS;
            vm.Processor.PrefixCount++;
        }
        [Opcode("66", Name = "opsize:", IsPrefix = true, OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void OperandSize(VirtualMachine vm)
        {
            vm.Processor.SizeOverride |= 1u;
            vm.Processor.PrefixCount++;
        }
        [Opcode("67", Name = "adrsize:", IsPrefix = true, OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void AddressSize(VirtualMachine vm)
        {
            vm.Processor.SizeOverride |= 2u;
            vm.Processor.PrefixCount++;
        }
        [Opcode("F2", Name = "repne:", IsPrefix = true, OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void Repne(VirtualMachine vm)
        {
            vm.Processor.RepeatPrefix = RepeatPrefix.Repne;
            vm.Processor.PrefixCount++;
        }
        [Opcode("F3", Name = "repe:", IsPrefix = true, OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void Repe(VirtualMachine vm)
        {
            vm.Processor.RepeatPrefix = RepeatPrefix.Repe;
            vm.Processor.PrefixCount++;
        }
    }
}
